package com.example.jiancaiwang.model;

import com.example.jiancaiwang.callback.MyOkhttpCallBack;
import com.example.jiancaiwang.utils.OkhttpUtils;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * model：获取网络数据
 */
public class HomeModel {
    //首页轮播图
    public void getBannerData(String url, final MyOkhttpCallBack myOkhttpCallBack){
        OkhttpUtils.getInstance().doGet(url,myOkhttpCallBack);
//        //TODO 1:client对象
//        OkHttpClient client = new OkHttpClient.Builder().build();
//        //TODO 2：requst请求对象
//        Request request = new Request.Builder()
//                .get()
//                .url(url)
//                .build();
//        //TODO 3:client发起请求
//        client.newCall(request).enqueue(new Callback() {
//            @Override
//            public void onFailure(Call call, IOException e) {
//                String message = e.getMessage();
//                myOkhttpCallBack.onError(message);
//            }
//
//            @Override
//            public void onResponse(Call call, Response response) throws IOException {
//                String string = response.body().string();
//                myOkhttpCallBack.onOk(string);
//            }
//        });

    }

    //首页菜单
    public void getMenuData(String url, MyOkhttpCallBack myOkhttpCallBack){
        OkhttpUtils.getInstance().doGet(url,myOkhttpCallBack);
    }


    //首页分类
    public void getTypeData(String url, MyOkhttpCallBack myOkhttpCallBack){
        OkhttpUtils.getInstance().doGet(url,myOkhttpCallBack);
    }
}
